'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {

  /* 渲染登录页 */
  async index() {
    const { ctx } = this;
    ctx.body = 'hi, egg';
  }

  /* 处理登录的函数 */
  async doLogin() {
    const username = this.ctx.request.body.username;
    const password = this.ctx.request.body.password;
    if (username === 'xiaoming' && password === '123') {
      this.ctx.session.user = username;
      this.ctx.redirect('/');
    } else {
      this.ctx.redirect('/login');
    }
  }
  /* 注销 */
  async logout() {
    this.ctx.session.user = '';
    this.ctx.redirect('/login');
  }
}

module.exports = HomeController;
